// AwardsController.java - 使用工厂方法创建领域对象
package com.elm.controller;

import com.elm.po.Awards;
import com.elm.service.AwardsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/api/awards")
public class AwardsController {

    @Autowired
    private AwardsService awardsService;

    @GetMapping("/get")
    public List<Awards> getAwards() {
        return awardsService.getAwards();
    }

    @PostMapping("/change")
    public boolean updateAwards(@RequestParam Long id,
                                @RequestParam BigDecimal recharge_amount,
                                @RequestParam BigDecimal award_amount) {
        return awardsService.updateAwards(id, recharge_amount, award_amount);
    }

    @PostMapping("/add")
    public boolean addAwards(@RequestParam Long id,
                             @RequestParam BigDecimal recharge_amount,
                             @RequestParam BigDecimal award_amount) {
        // 充血模型：使用工厂方法创建领域对象
        Awards awards = Awards.createAwards(id, recharge_amount, award_amount);
        return awardsService.addAwards(awards);
    }

    @PostMapping("/delete")
    public boolean deleteAwards(@RequestParam Long id){
        return awardsService.deleteAwards(id);
    }
}